package com.example.link.testfragment.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.link.testfragment.R;
import com.gigamole.infinitecycleviewpager.VerticalInfiniteCycleViewPager;

import java.util.ArrayList;
import java.util.List;


public class PlusTwoFragment extends Fragment {
    private List<Fragment> fragmentList;
    private View view;

    public PlusTwoFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_plus_two, container, false);
        fragmentList = new ArrayList<>();
        fragmentList.add(new OneFragmentInside1());
        fragmentList.add(new OneFragmentInside2());
        //fragmentList.add(new OneFragmentInside3());
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        final VerticalInfiniteCycleViewPager verticalInfiniteCycleViewPager = (VerticalInfiniteCycleViewPager) view.findViewById(R.id.vicvp);
        verticalInfiniteCycleViewPager.setAdapter(new myVerticalPager(getChildFragmentManager()));
    }

    /**
     * 初始化Fragment适配器
     */
    class myVerticalPager extends FragmentPagerAdapter {

        public myVerticalPager(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Override
        public int getCount() {
            return fragmentList.size();
        }
    }
}
